using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using AdCom.Utility;

namespace VDC.VONE.DAL
{

    #region About
    /// <summary>
	/// Class NguoidungData
	/// Gen by GenCode.NET - VDC
	/// 5/16/2008 9:13:40 AM
	/// </summary>
	#endregion

	public class NguoidungData
	{
		#region Contructor
		public NguoidungData()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#endregion
		//--------------------------------
		#region GetNguoidung
		public DataTable GetNguoidung()
		{
			DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GET",
				new SqlParameter[]{
					new SqlParameter("@id_nguoi_dung",System.DBNull.Value),
					new SqlParameter("@id_don_vi",System.DBNull.Value),
					new SqlParameter("@id_chuc_danh",System.DBNull.Value),
					new SqlParameter("@ten_dang_nhap",System.DBNull.Value),
					//new SqlParameter("@anh_avatar",System.DBNull.Value),
					new SqlParameter("@ho_va_ten",System.DBNull.Value),
					new SqlParameter("@gioi_tinh",System.DBNull.Value),
					new SqlParameter("@ngay_sinh",System.DBNull.Value),
					new SqlParameter("@thang_sinh",System.DBNull.Value),
					new SqlParameter("@nam_sinh",System.DBNull.Value),
					new SqlParameter("@dc_email",System.DBNull.Value),
					new SqlParameter("@dt_co_dinh",System.DBNull.Value),
					new SqlParameter("@dt_di_dong",System.DBNull.Value),
					//new SqlParameter("@email_dien_thoai",System.DBNull.Value),
					new SqlParameter("@dc_website",System.DBNull.Value),
					new SqlParameter("@dia_chi",System.DBNull.Value),
					new SqlParameter("@tinh_thanh",System.DBNull.Value),
					new SqlParameter("@ngay_tao",System.DBNull.Value)
					});
			return dt;
		}
        public DataTable GetNguoidungByQuyen(string p_RoleName)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GetUsersInRoles",
                new SqlParameter[]{
					
					new SqlParameter("@RoleName",p_RoleName)
					});
            return dt;
        }
        public DataTable GetNguoidungDonviByQuyen(string p_RoleName, int p_Unit)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GetUsersInRolesAndUnit",
                new SqlParameter[]{
					
					new SqlParameter("@RoleName",p_RoleName),
                    new SqlParameter("@Unit",p_Unit)
					});
            return dt;
        }
        public DataTable GetNguoidungByChucVu(string nhom, string strChucDanh, int id_don_vi)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_Get_By_Nhom_Va_ChucVu_1",
                new SqlParameter[]{
					new SqlParameter("@nhom",nhom),					
					new SqlParameter("@ma_chuc_danh",strChucDanh),					
					new SqlParameter("@id_don_vi",id_don_vi)
					});
            return dt;
        }
        public DataTable GetLanhDaoTrinhKy(string ten_dang_nhap)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_Get_LanhDaoTrinhKy",
                new SqlParameter[]{
								
					new SqlParameter("@ten_dang_nhap",ten_dang_nhap)
					
					});
            return dt;
        }
        public DataTable GetNguoidungByUserName(string username)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GET",
                new SqlParameter[]{
					new SqlParameter("@id_nguoi_dung",System.DBNull.Value),
					new SqlParameter("@id_don_vi",System.DBNull.Value),
					new SqlParameter("@id_chuc_danh",System.DBNull.Value),
					new SqlParameter("@ten_dang_nhap",username),
					//new SqlParameter("@anh_avatar",System.DBNull.Value),
					new SqlParameter("@ho_va_ten",System.DBNull.Value),
					new SqlParameter("@gioi_tinh",System.DBNull.Value),
					new SqlParameter("@ngay_sinh",System.DBNull.Value),
					new SqlParameter("@thang_sinh",System.DBNull.Value),
					new SqlParameter("@nam_sinh",System.DBNull.Value),
					new SqlParameter("@dc_email",System.DBNull.Value),
					new SqlParameter("@dt_co_dinh",System.DBNull.Value),
					new SqlParameter("@dt_di_dong",System.DBNull.Value),
					//new SqlParameter("@email_dien_thoai",System.DBNull.Value),
					new SqlParameter("@dc_website",System.DBNull.Value),
					new SqlParameter("@dia_chi",System.DBNull.Value),
					new SqlParameter("@tinh_thanh",System.DBNull.Value),
					new SqlParameter("@ngay_tao",System.DBNull.Value)
					});
            return dt;
        }
        public DataTable GetNguoidung_By_MaDonVi(string ma_don_vi)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GET_By_Madonvi",
                new SqlParameter[]{
					new SqlParameter("@ma_don_vi",ma_don_vi)
					});
            return dt;
        }
		//--------------------------------
		public DataTable GetNguoidungByID(int id_nguoi_dung)
		{
			DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GET",
				new SqlParameter[]{
					new SqlParameter("@id_nguoi_dung",id_nguoi_dung),
					new SqlParameter("@id_don_vi",System.DBNull.Value),
					new SqlParameter("@id_chuc_danh",System.DBNull.Value),
					new SqlParameter("@ten_dang_nhap",System.DBNull.Value),
					//new SqlParameter("@anh_avatar",System.DBNull.Value),
					new SqlParameter("@ho_va_ten",System.DBNull.Value),
					new SqlParameter("@gioi_tinh",System.DBNull.Value),
					new SqlParameter("@ngay_sinh",System.DBNull.Value),
					new SqlParameter("@thang_sinh",System.DBNull.Value),
					new SqlParameter("@nam_sinh",System.DBNull.Value),
					new SqlParameter("@dc_email",System.DBNull.Value),
					new SqlParameter("@dt_co_dinh",System.DBNull.Value),
					new SqlParameter("@dt_di_dong",System.DBNull.Value),
					//new SqlParameter("@email_dien_thoai",System.DBNull.Value),
					new SqlParameter("@dc_website",System.DBNull.Value),
					new SqlParameter("@dia_chi",System.DBNull.Value),
					new SqlParameter("@tinh_thanh",System.DBNull.Value),
					new SqlParameter("@ngay_tao",System.DBNull.Value)
					});
			return dt;
		}
        public DataTable GetNguoidungXulyVanban(int id_cong_van, string ten_dang_nhap)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GET_XulyVanban",
                new SqlParameter[]{
					new SqlParameter("@id_cong_van",id_cong_van),
					new SqlParameter("@ten_dang_nhap",ten_dang_nhap)
					});
            return dt;
        }
		//--------------------------------
        public void BindData(ref SqlDataSource sqlData, int id_don_vi, int id_chuc_danh, string ten_dang_nhap, string ho_va_ten)
		{
			AdSqlDataSource.CallSelectStore(ref sqlData, "MIS_nguoi_dung_GET",
				new SqlParameter[]{
					new SqlParameter("id_nguoi_dung",System.DBNull.Value),
					new SqlParameter("id_don_vi",id_don_vi),
					new SqlParameter("id_chuc_danh",id_chuc_danh),
                    new SqlParameter("ten_dang_nhap",ten_dang_nhap),
                    //new SqlParameter("anh_avatar",anh_avatar),
                    new SqlParameter("ho_va_ten",ho_va_ten)
                    //new SqlParameter("gioi_tinh",gioi_tinh),
                    //new SqlParameter("ngay_sinh",ngay_sinh),
                    //new SqlParameter("thang_sinh",thang_sinh),
                    //new SqlParameter("nam_sinh",nam_sinh),
                    //new SqlParameter("dc_email",dc_email),
                    //new SqlParameter("dt_co_dinh",dt_co_dinh),
                    //new SqlParameter("dt_di_dong",dt_di_dong),
                    //new SqlParameter("email_dien_thoai",email_dien_thoai),
                    //new SqlParameter("dc_website",dc_website),
                    //new SqlParameter("dia_chi",dia_chi),
                    //new SqlParameter("tinh_thanh",tinh_thanh),
                    //new SqlParameter("ngay_tao",ngay_tao)
					});
		}
		//--------------------------------
		#endregion
		//--------------------------------
		#region InsertNguoidung
		public int InsertNguoidung(int id_don_vi, int id_chuc_danh, string ten_dang_nhap, string anh_avatar, string ho_va_ten, int gioi_tinh, int ngay_sinh, int thang_sinh, int nam_sinh, string dc_email, string dt_co_dinh, string dt_di_dong, string email_dien_thoai, string dc_website, string dia_chi, string tinh_thanh, string ngay_tao, int cvtt, string ma)
		{
			int i = (int)SqlDataHelper.CallActionStoredProcedure("MIS_nguoi_dung_SET",
					new SqlParameter[]{
						new SqlParameter("@id_nguoi_dung",System.DBNull.Value),
						new SqlParameter("@id_don_vi",id_don_vi),
						new SqlParameter("@id_chuc_danh",id_chuc_danh),
						new SqlParameter("@ten_dang_nhap",ten_dang_nhap),
						new SqlParameter("@anh_avatar",anh_avatar),
						new SqlParameter("@ho_va_ten",ho_va_ten),
						new SqlParameter("@gioi_tinh",gioi_tinh),
						new SqlParameter("@ngay_sinh",ngay_sinh),
						new SqlParameter("@thang_sinh",thang_sinh),
						new SqlParameter("@nam_sinh",nam_sinh),
						new SqlParameter("@dc_email",dc_email),
						new SqlParameter("@dt_co_dinh",dt_co_dinh),
						new SqlParameter("@dt_di_dong",dt_di_dong),
						new SqlParameter("@email_dien_thoai",email_dien_thoai),
						new SqlParameter("@dc_website",dc_website),
						new SqlParameter("@dia_chi",dia_chi),
						new SqlParameter("@tinh_thanh",tinh_thanh),
						new SqlParameter("@ngay_tao",ngay_tao),
                        new SqlParameter("@cvtt",cvtt),
                        new SqlParameter("@ma",ma),
						new SqlParameter("@AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
						});
			return i;
		}
		#endregion
		//--------------------------------
		#region UpdateNguoidung
        public int UpdateNguoidung(int id_nguoi_dung, int id_don_vi, int id_chuc_danh, string ten_dang_nhap, string anh_avatar, string ho_va_ten, int gioi_tinh, int ngay_sinh, int thang_sinh, int nam_sinh, string dc_email, string dt_co_dinh, string dt_di_dong, string email_dien_thoai, string dc_website, string dia_chi, string tinh_thanh, string ngay_tao, int cvtt, string ma)
		{
			int i = (int)SqlDataHelper.CallActionStoredProcedure("MIS_nguoi_dung_SET",
					new SqlParameter[]{
						new SqlParameter("@id_nguoi_dung",id_nguoi_dung),
						new SqlParameter("@id_don_vi",id_don_vi),
						new SqlParameter("@id_chuc_danh",id_chuc_danh),
						new SqlParameter("@ten_dang_nhap",ten_dang_nhap),
						//new SqlParameter("@anh_avatar",anh_avatar),
						new SqlParameter("@ho_va_ten",ho_va_ten),
						new SqlParameter("@gioi_tinh",gioi_tinh),
						new SqlParameter("@ngay_sinh",ngay_sinh),
						new SqlParameter("@thang_sinh",thang_sinh),
						new SqlParameter("@nam_sinh",nam_sinh),
						new SqlParameter("@dc_email",dc_email),
						new SqlParameter("@dt_co_dinh",dt_co_dinh),
						new SqlParameter("@dt_di_dong",dt_di_dong),
						//new SqlParameter("@email_dien_thoai",email_dien_thoai),
						new SqlParameter("@dc_website",dc_website),
						new SqlParameter("@dia_chi",dia_chi),
						new SqlParameter("@tinh_thanh",tinh_thanh),
						new SqlParameter("@ngay_tao",ngay_tao),
                        new SqlParameter("@cvtt",cvtt),
                        new SqlParameter("@ma",ma),
						new SqlParameter("@AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
						});
			return i;
		}
        public int UpdateNguoidungOnline(string username, int dang_online)
        {
            int i = (int)SqlDataHelper.CallActionStoredProcedure("MIS_nguoi_dung_SET_Online",
                    new SqlParameter[]{
						new SqlParameter("@ten_dang_nhap",username),
						new SqlParameter("@dang_online",dang_online)
						});
            return i;
        }
        public DataTable GetAllNguoidungOnline()
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_Get_AllOnline",
                null);
            return dt;
        }
		#endregion
		//--------------------------------
		#region DeleteNguoidung
		/// <summary>
		///     Thu tuc xoa bang khoa chinh
		/// </summary>
		public void DeleteNguoidungByID(ref SqlDataSource sqd, int id_nguoi_dung)
		{
			AdSqlDataSource.CallDeleteStore(ref sqd, "MIS_nguoi_dung_DELETE",
				new SqlParameter[]{
					new SqlParameter("id_nguoi_dung",id_nguoi_dung),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
			sqd.Delete();
		}
		//------------------------------------//
		public void DeleteNguoidungByID(int id_nguoi_dung)
		{
			new AdSqlDataLocalHelper().CallActionStoredProcedure("MIS_nguoi_dung_DELETE",
				new SqlParameter[]{
					new SqlParameter("id_nguoi_dung",id_nguoi_dung),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
		}
		//------------------------------------//
		public void DeleteNguoidungByIDFKey(int id_don_vi)
		{
			new AdSqlDataLocalHelper().CallActionStoredProcedure("MIS_nguoi_dung_DELETE",
				new SqlParameter[]{
					new SqlParameter("id_nguoi_dung",System.DBNull.Value),
					new SqlParameter("id_don_vi",id_don_vi),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
		}
		//------------------------------------//
		public void DeleteNguoidungByIDFKey_Chucdanh(int id_chuc_danh)
		{
			new AdSqlDataLocalHelper().CallActionStoredProcedure("MIS_nguoi_dung_DELETE",
				new SqlParameter[]{
					new SqlParameter("id_nguoi_dung",System.DBNull.Value),
					new SqlParameter("id_chuc_danh",id_chuc_danh),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
		}
		//--------------------------------
		/// <summary>
		///     Thu tuc xoa nhieu item do nguoi dung lua chon
		/// </summary>
		public void DeleteNguoidungAll(ref SqlDataSource sqd, string strID)
		{
			AdSqlDataSource.CallDeleteStore(ref sqd, "MIS_nguoi_dung_DELETEAll",
				new SqlParameter[]{
					new SqlParameter("strid_nguoi_dung",strID),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
			sqd.Delete();
		}
		public void DeleteNguoidungAllFKey(string id_don_vi)
		{
			new AdSqlDataLocalHelper().CallActionStoredProcedure("MIS_nguoi_dung_DELETEAll",
				new SqlParameter[]{
					new SqlParameter("strid_nguoi_dung",System.DBNull.Value),
					new SqlParameter("strid_don_vi",id_don_vi),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
		}

		#region command
		public string GetStringID(string strid_don_vi,int id)
		{
			AdCom.Utility.AdSqlDataLocalHelper ash = new AdSqlDataLocalHelper();
			return ash.SelectScalarString(strid_don_vi, "nguoi_dung","id_nguoi_dung=" + AdCom.Utility.SqlDataHelper.EscapeQuote(id.ToString()));
		}
		#endregion
		public void DeleteNguoidungAllFKey_Chucdanh(string id_chuc_danh)
		{
			new AdSqlDataLocalHelper().CallActionStoredProcedure("MIS_nguoi_dung_DELETEAll",
				new SqlParameter[]{
					new SqlParameter("strid_nguoi_dung",System.DBNull.Value),
					new SqlParameter("strid_chuc_danh",id_chuc_danh),
					new SqlParameter("AdComUserName",System.Web.HttpContext.Current.User.Identity.Name)
				});
		}

		#region command
		public string GetStringID_Chucdanh(string strid_chuc_danh,int id)
		{
			AdCom.Utility.AdSqlDataLocalHelper ash = new AdSqlDataLocalHelper();
			return ash.SelectScalarString(strid_chuc_danh, "nguoi_dung","id_nguoi_dung=" + AdCom.Utility.SqlDataHelper.EscapeQuote(id.ToString()));
		}
		#endregion
		#endregion
        #region Get Don Vi(LNHAI)
        public DataTable GetNguoiDungAll(int id_don_vi)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GetAll",
                new SqlParameter[]{
					new SqlParameter("@id_nguoi_dung",System.DBNull.Value),
					new SqlParameter("@id_don_vi",id_don_vi),
					new SqlParameter("@id_chuc_danh",System.DBNull.Value),
					new SqlParameter("@ten_dang_nhap",System.DBNull.Value),
                    //new SqWlParameter("@anh_avatar",System.DBNull.Value),
					new SqlParameter("@ho_va_ten",System.DBNull.Value),
                    new SqlParameter("@gioi_tinh",System.DBNull.Value),
                    new SqlParameter("@ngay_sinh",System.DBNull.Value),
                    new SqlParameter("@thang_sinh",System.DBNull.Value),
                    new SqlParameter("@nam_sinh",System.DBNull.Value),
                    new SqlParameter("@dc_email",System.DBNull.Value),
                    new SqlParameter("@dt_co_dinh",System.DBNull.Value),
                    new SqlParameter("@dt_di_dong",System.DBNull.Value),
                    //new SqlParameter("@email_dien_thoai",System.DBNull.Value),
                    new SqlParameter("@dc_website",System.DBNull.Value),
                    new SqlParameter("@dia_chi",System.DBNull.Value),
                    new SqlParameter("@tinh_thanh",System.DBNull.Value),
                    new SqlParameter("@ngay_tao",System.DBNull.Value)
					});
            return dt;
        }
        #endregion

        #region Get Name By ID
        public DataTable Get_Name_By_ID(int id_nguoi_dung)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_Get_name_by_id",
                new SqlParameter[]{					
                    new SqlParameter("@id_nguoi_dung",id_nguoi_dung),                   
                    new SqlParameter("@ten_dang_nhap",System.DBNull.Value)
					});
            return dt;
        }
        #endregion

       

        #region
        public void BindGridView(ref SqlDataSource sqlData, int id_don_vi, int id_chuc_danh, string ten_dang_nhap)
        {
            AdSqlDataSource.CallSelectStore(ref sqlData, "MIS_nguoi_dung_GET",
                new SqlParameter[]{
					new SqlParameter("id_nguoi_dung",System.DBNull.Value),
					new SqlParameter("id_don_vi",id_don_vi),
					new SqlParameter("ten_dang_nhap",ten_dang_nhap),
                    new SqlParameter("id_chuc_danh",id_chuc_danh),
                    //new SqlParameter("anh_avatar",anh_avatar),
                    //new SqlParameter("ho_va_ten",System.DBNull.Value),
                    //new SqlParameter("gioi_tinh",gioi_tinh),
                    //new SqlParameter("ngay_sinh",ngay_sinh),
                    //new SqlParameter("thang_sinh",thang_sinh),
                    //new SqlParameter("nam_sinh",nam_sinh),
                    //new SqlParameter("dc_email",dc_email),
                    //new SqlParameter("dt_co_dinh",dt_co_dinh),
                    //new SqlParameter("dt_di_dong",dt_di_dong),
                    //new SqlParameter("email_dien_thoai",email_dien_thoai),
                    //new SqlParameter("dc_website",dc_website),
                    //new SqlParameter("dia_chi",dia_chi),
                    //new SqlParameter("tinh_thanh",tinh_thanh),
					//new SqlParameter("ngay_tao",System.DBNull.Value)
					});
        }
        #endregion

        #region GET max id nguoi dung
        public DataTable GET_Max_id_nguoidung()
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GET_MAX_ID",
                new SqlParameter[]{					
                    new SqlParameter("@id_nguoi_dung",System.DBNull.Value)                 
					});
            return dt;
        }
        #endregion

        #region Get nguoi dung by id_nguoi_dung
        public DataTable GET_nguoidung_by_id_nguoidung(int id_nguoi_dung)
        {
            DataTable dt = SqlDataHelper.CallRetrievalStoredProcedure("MIS_nguoi_dung_GET_by_id_nguoi_dung",
                new SqlParameter[]{					
                    new SqlParameter("@id_nguoi_dung",id_nguoi_dung)                 
					});
            return dt;
        }
        #endregion
    }
}
